﻿using Net.Client;
using Net.Helper;
using Net.Share;
using System;

namespace Net.Server
{
    public partial class ClientPeer
    {
        #region 不异步时内置Token
        public void Response(uint protocol, SyncSerialize serialize, params object[] pars)
            => Call(NetCmd.CallRpc, protocol, true, serialize, Token, null, pars);
        public void Response(uint protocol, params object[] pars)
            => Call(NetCmd.CallRpc, protocol, true, SyncSerialize.False, Token, null, pars);
        public void Response(NetCmd cmd, uint protocol, params object[] pars)
            => Call(cmd, protocol, true, SyncSerialize.False, Token, null, pars);

        public void Response(string func, SyncSerialize serialize, params object[] pars)
            => Call(NetCmd.CallRpc, func.CRCU32(), true, serialize, Token, null, pars);
        public void Response(string func, params object[] pars)
            => Call(NetCmd.CallRpc, func.CRCU32(), true, SyncSerialize.False, Token, null, pars);
        public void Response(NetCmd cmd, string func, params object[] pars)
            => Call(cmd, func.CRCU32(), true, SyncSerialize.False, Token, null, pars);
        #endregion

        #region 提供枚举协议类型
        public void Call(Enum protocol, params object[] pars)
            => Call(NetCmd.CallRpc, (uint)protocol.GetHashCode(), true, SyncSerialize.False, RequestToken.Default, null, pars);
        public void Call(NetCmd cmd, Enum protocol, params object[] pars)
            => Call(cmd, (uint)protocol.GetHashCode(), true, SyncSerialize.False, RequestToken.Default, null, pars);
        public void Response(Enum protocol, SyncSerialize serialize, in RequestToken token, params object[] pars)
            => Call(NetCmd.CallRpc, (uint)protocol.GetHashCode(), true, serialize, token, null, pars);
        public void Response(Enum protocol, in RequestToken token, params object[] pars)
            => Call(NetCmd.CallRpc, (uint)protocol.GetHashCode(), true, SyncSerialize.False, token, null, pars);
        public void Response(NetCmd cmd, Enum protocol, in RequestToken token, params object[] pars)
            => Call(cmd, (uint)protocol.GetHashCode(), true, SyncSerialize.False, token, null, pars);

        public void Response(Enum protocol, SyncSerialize serialize, params object[] pars)
            => Call(NetCmd.CallRpc, (uint)protocol.GetHashCode(), true, serialize, Token, null, pars);
        public void Response(Enum protocol, params object[] pars)
            => Call(NetCmd.CallRpc, (uint)protocol.GetHashCode(), true, SyncSerialize.False, Token, null, pars);
        public void Response(NetCmd cmd, Enum protocol, params object[] pars)
            => Call(cmd, (uint)protocol.GetHashCode(), true, SyncSerialize.False, Token, null, pars);
        #endregion

        public void AddRpc(object target, AddRpcMode mode = AddRpcMode.None) => RpcAdapter.AddRpc(target, mode);
        public void RemoveRpc(object target) => RpcAdapter.RemoveRpc(target);
    }
}